package com.zhaojiadi.factory.store;

import com.zhaojiadi.factory.store.impl.CardCommodityService;
import com.zhaojiadi.factory.store.impl.CouponCommodityService;
import com.zhaojiadi.factory.store.impl.GoodsCommodityService;

import java.util.Objects;

/**
 * @Date: 2021/8/23
 * @Description:
 */
public class StoreFactory {

    /**
     * 奖品类型方式实例化
     */
    public ICommodity getCommodityService(Integer commodityType) {
        if (Objects.isNull(commodityType)) throw new IllegalArgumentException("参数错误");
        else if (1 == commodityType) return new CouponCommodityService();
        else if (2 == commodityType) return new GoodsCommodityService();
        else if (3 == commodityType) return new CardCommodityService();
        throw new IllegalArgumentException();
    }

    public ICommodity getCommodityService(Class<? extends ICommodity> clazz) throws IllegalAccessException, InstantiationException {
        if(Objects.isNull(clazz)) return null;
        return clazz.newInstance();
    }
}
